<?php 
class ControllerMessagePosition extends Controller {
	public function index() {  
		$this->language->load('message/position');

		$this->load->model('message/position');

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
			'separator' => false
		);

		if (isset($this->request->get['send_name'])) {
			$send_name = $this->request->get['send_name'];
		} else {
			$send_name = '';
		}
		
		$this->data['positionInfos'] = array();
		$this->load->model('message/community');
		$communities = $this->model_message_community->getAllCommunities();
		if($communities){
			foreach ($communities as $community) {
				$this->data['positionInfos'][] = array(
					'phone_num'=>$community['phone_num'],
					'name'=>$community['title'],
					'lat'=>doubleval($community['lat']),
					'lng'=>doubleval($community['lng']),
				);
			}
		}
		$sender_info = $this->model_message_position->getSenderPosition($send_name);
		
		$this->data['placeName'] =false;
		if ($sender_info) {
			$this->data['sender_info'] = array(
				'address'=>$sender_info['label'],
			);
		} else {
			$this->data['sender_info'] = array(
				'address'=>'',
			);
		}
		$this->load->model('message/card_manage');
		$this->data['cardManages'] = $this->model_message_card_manage->getAllCardManage();
	
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/message/send_info.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/message/send_info.tpl';
			} else {
				$this->template = 'default/template/message/send_info.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);

			$this->response->setOutput($this->render());
	}

	public function info() {
		$this->load->model('catalog/information');

		if (isset($this->request->get['information_id'])) {
			$information_id = (int)$this->request->get['information_id'];
		} else {
			$information_id = 0;
		}      

		$information_info = $this->model_catalog_information->getInformation($information_id);

		if ($information_info) {
			$output  = '<html dir="ltr" lang="en">' . "\n";
			$output .= '<head>' . "\n";
			$output .= '  <title>' . $information_info['title'] . '</title>' . "\n";
			$output .= '  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
			$output .= '  <meta name="robots" content="noindex">' . "\n";
			$output .= '</head>' . "\n";
			$output .= '<body>' . "\n";
			$output .= '  <h1>' . $information_info['title'] . '</h1>' . "\n";
			$output .= html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8') . "\n";
			$output .= '  </body>' . "\n";
			$output .= '</html>' . "\n";			

			$this->response->setOutput($output);
		}
	}
	
	private function curlGet($url, $params = array(), $option = array()) {



		if (!empty($params)) {

			$p = http_build_query($params);



			if (FALSE === strpos('?', $url)) {

				$url = $url . '?' . $p;

			} else {

				$url = $url . '&' . $p;

			}

		}

		$ch = curl_init($url);


		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt_array($ch, $option);



		$result = curl_exec($ch);

		curl_close($ch);



		return $result ? $result : false;

	}
}
?>